package com.zshan.clinic.web.controller.medical;


import com.zshan.clinic.admin.entity.vo.ClinicQueueVo;
import com.zshan.clinic.admin.entity.vo.QueueBoardVo;
import com.zshan.clinic.admin.service.medical.ClinicQueueService;
import com.zshan.clinic.common.entity.HeaderDTO;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.database.model.ClinicQueue;
import com.zshan.clinic.web.annotation.Permission;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 挂号
 */
@RestController
@RequestMapping("/clinic/queue")
public class ClinicQueueController extends AbstractController {


    @Autowired
    private ClinicQueueService clinicQueueService;

    /**
     * 获取门诊叫号看板
     * @return
     */
    @GetMapping("/getBoardList")
    @Permission
    public RestResp<List<QueueBoardVo>> getBoardList() {
        HeaderDTO headerDTO = getHeader();
        List<QueueBoardVo> queueVoList = clinicQueueService.getBoardList(headerDTO.getClinicId());
        return RestResp.SUCCESS(queueVoList);
    }



    /**
     * 叫号：获取候诊列表
     * @return
     */
    @GetMapping("/getReadyList")
    public RestResp<List<ClinicQueueVo>> getReadyList() {
        UserInfo userInfo = getUserInfo();
        List<ClinicQueueVo> queueVoList = clinicQueueService.getReadyList(userInfo.getClinicId(),userInfo.getEmpId());
        return RestResp.SUCCESS(queueVoList);
    }


    /**
     * 叫号：获取待诊列表
     * @return
     */
    @GetMapping("/getWaitingList")
    public RestResp<List<ClinicQueueVo>> getWaitingList() {
        UserInfo userInfo = getUserInfo();
        List<ClinicQueueVo> queueVoList = clinicQueueService.getWaitingList(userInfo.getClinicId(),userInfo.getEmpId());
        return RestResp.SUCCESS(queueVoList);
    }

    /**
     * 叫号：获取呼叫中的患者
     * @return
     */
    @GetMapping("/getCalled")
    public RestResp<ClinicQueueVo> getCalled() {
        UserInfo userInfo = getUserInfo();
        ClinicQueueVo clinicQueueVo = clinicQueueService.getCalled(userInfo.getClinicId(),userInfo.getEmpId());
        return RestResp.SUCCESS(clinicQueueVo);
    }

    /**
     * 叫号：获取完诊列表
     * @return
     */
    @GetMapping("/getTreatedList")
    public RestResp<List<ClinicQueueVo>> getTreatedList() {
        UserInfo userInfo = getUserInfo();
        List<ClinicQueueVo> queueVoList = clinicQueueService.getTreatedList(userInfo.getClinicId(),userInfo.getEmpId());
        return RestResp.SUCCESS(queueVoList);
    }

    /**
     * 叫号：呼叫下一位
     * @param clinicQueue
     * @return
     */
    @PostMapping("/callNext")
    public RestResp<Void> callNext(@RequestBody ClinicQueue clinicQueue) {
        UserInfo userInfo = getUserInfo();
        clinicQueue.setUpdateUserId(userInfo.getEmpId());
        clinicQueue.setUpdateBy(userInfo.getEmpName());
        clinicQueue.setClinicId(userInfo.getClinicId());
        clinicQueueService.callNext(clinicQueue);
        return RestResp.SUCCESS();
    }


    /**
     * 重新呼叫
     * @param clinicQueue
     * @return
     */
    @PostMapping("/repeatCall")
    public RestResp<Void> repeatCall(@RequestBody ClinicQueue clinicQueue) {
        UserInfo userInfo = getUserInfo();
        clinicQueue.setUpdateUserId(userInfo.getEmpId());
        clinicQueue.setUpdateBy(userInfo.getEmpName());
        clinicQueue.setClinicId(userInfo.getClinicId());
        clinicQueueService.repeatCall(clinicQueue);
        return RestResp.SUCCESS();
    }

    /**
     * 叫号：过号
     * @param clinicQueue
     * @return
     */
    @PostMapping("/missed")
    public RestResp<Void> missed(@RequestBody ClinicQueue clinicQueue) {
        UserInfo userInfo = getUserInfo();
        clinicQueue.setUpdateUserId(userInfo.getEmpId());
        clinicQueue.setUpdateBy(userInfo.getEmpName());
        clinicQueue.setClinicId(userInfo.getClinicId());
        clinicQueueService.missed(clinicQueue);
        return RestResp.SUCCESS();
    }

    /**
     * 叫号：重新排队
     * @param clinicQueue
     * @return
     */
    @PostMapping("/repeatWait")
    public RestResp<Void> repeatWait(@RequestBody ClinicQueue clinicQueue) {
        UserInfo userInfo = getUserInfo();
        clinicQueue.setUpdateUserId(userInfo.getEmpId());
        clinicQueue.setUpdateBy(userInfo.getEmpName());
        clinicQueue.setClinicId(userInfo.getClinicId());
        clinicQueueService.repeatWait(clinicQueue);
        return RestResp.SUCCESS();
    }

}
